package com.gofbox;

import com.gofbox.util.FileUtil;

import java.io.FileWriter;

/**
 * Created by aoc on 2016/10/31.
 */
public class InterfaceMain {
    /**
     * 文件内容
     *
     * @param entityName
     * @return
     */
    public static String createBody(String entityName, String packageName) {
        String packagedir = "package " + packageName + "; \n";
        String head = "public interface I" + entityName + "Remote {\n";
        String end = "}";

        StringBuffer sb = new StringBuffer();
        sb.append(
                "    public List<ApiStore> get" + entityName + "(List<Long> ids, int start, int end);\n" +
                        "    public boolean add" + entityName + "(" + entityName + " " + entityNameToUp(entityName) + ");\n" +
                        "    public boolean update" + entityName + "(" + entityName + " " + entityNameToUp(entityName) + ");\n" +
                        "    public boolean del" + entityName + "(" + entityName + " " + entityNameToUp(entityName) + ");\n" +
                        "    public List<" + entityName + "> get" + entityName + "ByAll(List<Long> ids);\n");

        return packagedir + head + sb.toString() + end;
    }

    public static String entityNameToUp(String str) {

        if (str != null) {
            String[] result = {str.substring(0, 1), str.substring(1)};
            return result[0].toUpperCase() + result[1];
        }
        return "";
    }

    /**
     * 文件名
     *
     * @param entityName
     * @return
     */
    public static String createFile(String entityName) {
        String fileName = entityName + ".java";
        return fileName;
    }

    /**
     * 文件目录
     *
     * @param baseDir
     * @param packageName
     * @return
     */
    public static String filePath(String baseDir, String packageName) {
        String pathdir = packageName.replace(".", "/");
        return baseDir + "/src/main/java/" + pathdir;
    }

    public static void main(String[] args) {
        String fileName = String.valueOf(System.getProperty("user.dir")) + "/box-remote";
        String packageName = "com.gofbox.api.test";
        String fileurl = filePath(fileName, packageName) + "/";
        String bodyContent = createBody("Test", packageName);
        FileUtil.appendMethodB(fileurl,"ITestRemote.java", bodyContent);
    }
}
